no_std support w/o detection #89
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
spdxseems the best tool for the job of "software licenses as a type", and so I wish to use it in my library code. The only blocker is thatspdxis notno_std, which I would like my library to be capable of.So, as one does, I browsed the source code to see how
stdspdxreally was. To my delight, the answer seems to be "not very": Outside the optionaldetectionfeature, all uses ofstdare soundly covered either bycore, or byalloc(only needed forBox,Vec,String).Goals
This PR's goal is to perform the minimal amount of changes needed to realize a widely usable
Licensetype, without modifying any logic whatsoever.The core part of
spdx, including thetextfeature, should now work on anyno_stdplatform that supportsalloc. This includeswasm, for example.Non-Goals
spdxincl. features that really do needstd: Thedetectionfeature, in particular, makes legitimate use ofstd(HashMapandLazyLock). While there are doubtless good ways of achieving the same algorithms inno_std, they would differ in perhaps surprising ways. For example,HashMapandBTreeMaphave vastly different performance properties, and theno_stdways of doing aLazyLockhave serious tradeoffs - it would be wrong to naively impose these tradeoffs "just to make it work".no_stddifficult are not the right tool for the job. This is not one of those times -spdxis already architecturally capable ofno_std, and the "replacement types" are either identical, or effectively identical. For that reason, it doesn't make sense to suggest changes to types.spdxalready works, and the way thatspdxalready works relies legitimately onalloc. To insist on removingallocbeforeno_stdworks at all would be unfortunate.Maintenance Burden
I would argue that the maintenance burden of this PR is low, since no actual logic was changed.
In the future, one will have to default to using
core::andalloc::, instead ofstd::. If one really needs something instd, a decision will have to be made as to whether to feature-gate it behindstd, or whether to replace thestdthing with an appropriateno_stddependency.It is a certain kind of price to pay for the wider platform support of
no_std. But I would propose that this might actually be an upside. Arguably, a library providing a single data-oriented type doesn't need something non-optional fromstd, by virtue of being a nice way of interacting with a bag of bits. Anystd-dependent extras should probably be feature-gated anyway! If one agrees with that sentiment, then why not formalize the convention in a way that the compiler will yell about?Misc Notes
stdfeature is explicitly depended on by each feature that requires it, even though it's not strictly needed. This is to make it explicit what needsstdand what doesn't. Furthermore, in the future, if a feature is implemented forno_std, then that intention will be very obvious.rust_analyzerdoesn't always seem to catchno_stdonly problems when configured to enable all features by default. Some LSP configuration might be a good idea.